﻿using EFRepositoryDemo.Domain;
using System.Collections.Generic;
using System.Web.Http;
using System.Linq;
using System;
using EFRepositoryDemo.Repository;

namespace EFRepositoryDemo.API
{
    public class StuEducationController : ApiController
    {
        private readonly IStuAccountRepo _stuAccountRepo;
        private readonly IStuEducationRepo _stuEducationRepo;
        private readonly IUnitOfWork _unitOfWork;

        public StuEducationController(IStuAccountRepo stuAccountRepo, IStuEducationRepo stuEducationRepo, IUnitOfWork unitOfWork)
        {
            this._stuAccountRepo = stuAccountRepo;
            this._stuEducationRepo = stuEducationRepo;
            this._unitOfWork = unitOfWork;
        }

        // GET api/<controller>/5
        public string Get(int id)
        {

            var stuAccount = _stuAccountRepo.Get(p => p.UserId == 20987);
            if (stuAccount != null)
            {
                stuAccount.UserName = "张冬林Test";
            }

            var stuEducation = _stuEducationRepo.GetMany(p => p.UserId == 20987);
            if (stuEducation != null && stuEducation.Count() > 0)
            {
                foreach (var i in stuEducation)
                {
                    i.ModifyDate = new DateTime(2016, 06, 14);
                }
            }

            _unitOfWork.Commit();

            return "value";
        }

    }

}